package com.iss.springdemo1.mvc.controller;

import com.iss.springdemo1.mvc.model.ResponseMessage;
import com.iss.springdemo1.mvc.model.User;
import com.iss.springdemo1.mvc.service.UserService2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/user2")
public class UserController {

    @Autowired
    private UserService2 userService2;

    @RequestMapping("remove")
    @ResponseBody
    public ResponseMessage remove(@RequestParam("userid") int userid){
       return userService2.removeByUserId(userid);
    }

    @RequestMapping(value = "/list",method = RequestMethod.GET)
    @ResponseBody
    public List<User> list(){
        return  userService2.list();
    }

    @RequestMapping("index")
    public String rediect(){
        return  "index";
    }

    /*restful:  Post get Delete Put  */
    @GetMapping(value = "/list2/{role}")
    @ResponseBody
    public List<User> list2(@PathVariable int role,User user){
        System.out.println(user.getUsername());

      return   userService2.getListByRole(role);
    }

}
